import {PlayerModel} from "../../../adapterModel/model4/PlayerModel";
import {HurtType} from "../../../../dataSource/DataModel";
import {UnitModel} from "../../../adapterModel/model3/UnitModel";
import {RectModel} from "../../../adapterModel/model2/RectModel";
import {ItemModel} from "../../../adapterModel/model3/ItemModel";
import {LocModel} from "../../../base/LocModel";

export enum PlayerEvent {
    playerLeave = 1,
}

export enum PlayerUnitEvent {
    constructFinish = 1,
    unitAttacked,
    unitGetItem,
    unitDropItem,
    unitUseItem,
    unitBuyItem,
    unitSellItem,
    unitFinishUseSpell,
    unitBeforeUseSpell,
    unitLevelUp,
    unitDead,
}

export enum UnitEvent {
    unitDamage = 1
}

export enum DamageType {
    EVENT_DAMAGE_DATA_VAILD = 0,
    EVENT_DAMAGE_DATA_IS_PHYSICAL, //是否物理伤害
    EVENT_DAMAGE_DATA_IS_ATTACK, //是否攻击伤害
    EVENT_DAMAGE_DATA_IS_RANGED,//是否远程
    EVENT_DAMAGE_DATA_DAMAGE_TYPE,//伤害类型
    EVENT_DAMAGE_DATA_WEAPON_TYPE,//武器类型
    EVENT_DAMAGE_DATA_ATTACK_TYPE//攻击类型
}

export enum AttackType {
    // 法术
    ATTACK_TYPE_NORMAL = 0,
    // 普通
    ATTACK_TYPE_MELEE,
    // 穿刺
    ATTACK_TYPE_PIERCE,
    // 攻城
    ATTACK_TYPE_SIEGE,
    // 魔法
    ATTACK_TYPE_MAGIC,
    // 混乱
    ATTACK_TYPE_CHAOS,
    // 英雄
    ATTACK_TYPE_HERO,
}

export interface DamageInfo {
    attacker: UnitModel;
    attacked: UnitModel;
    damage: number;
    hurtType: HurtType;
}

export interface TransInfo {
    transUnit: UnitModel;
    rect: RectModel;
}

export interface ConstructInfo {
    constructUnit: UnitModel;
}

export interface WheelInfo {
    delta: number;
    player: PlayerModel
}

export interface UpdateInfo {
    player: PlayerModel
}

export interface SelectInfo {
    player: PlayerModel;
}

export interface AttackInfo {
    attacker: UnitModel;
    attacked: UnitModel;
}

export interface ManipulatingItemInfo {
    unit: UnitModel;
    item: ItemModel;
}
export interface SellItemInfo {
    sellUnit: UnitModel;
    buyUnit: UnitModel;
    item: ItemModel;
}

export enum MouseEventType {
    mouseLeftUp = 1,
    mouseLeftDown,
    mouseRightUp,
    mouseRightDown,
    mouseMove,
}

export interface MouseEventInfo {
    // startX: number;
    // startY: number;
    // screenX: number;
    // screenY: number;
    percentX: number;
    percentY: number;
    // gameX: number;
    // gameY: number;
    loc: LocModel;
    player: PlayerModel;
    type: MouseEventType;
    unit: UnitModel;

    bStop?: boolean;
    // width: number;
    // height: number;
}

export interface SpellInfo {
    useUnit: UnitModel;
    useItem: ItemModel;
    targetUnit: UnitModel;
    targetItem: ItemModel;
    spellLoc: LocModel;
    spellId: string;
}

export interface LevelUpInfo {
    unit: UnitModel;
    level: number;
}

export interface DeadInfo {
    killer: UnitModel;
    killed: UnitModel;
}

export interface InputInfo {
    str: string;
    player: PlayerModel;
}

export interface KeyEventInfo {
    player: PlayerModel;
    key: number;
}

export interface PlayerExitInfo {
    player: PlayerModel;
}

export interface SyncDataInfo {
    player: PlayerModel;
    str: string;
}

export let triggetAdapter: { adapter: ITriggerAdapter } = { adapter: undefined };

export interface ITriggerAdapter {
    createHandle(): any;
    addAction(handle: any, actionFunc: (this: void) => void): void;
    registerMouseWheel(handle: any, callBack: (this: void, bStop: boolean) => void, sync : boolean): void;
    registerUpdate(handle: any, callBack: (this: void) => void): void;
    registerAnyUnitEvent(handle: any, whichPlayerUnitEvent: PlayerUnitEvent): void
    registerCommandEvent(handle: any, whichAbility: number, order: string): void
    registerEnterRect(handle: any, whichRect: any): void
    registerLeaveRect(handle: any, whichRect: any): void
    registerUnitEvent(handle: any, whichUnit: any, whichEvent: UnitEvent): void
    registerAnyPlayerChatEvent(handle: any, players: any[], chatMessageToDetect: string, exactMatchOnly: boolean): void
    registerAnyPlayerEvent(handle: any, players: any[], playerEvent: PlayerEvent): void;
    registerPlayerSelected(handle: any, players: PlayerModel[], selected: boolean): void;
    registerKeyEvent(handle: any, key: number, state: number, sync: boolean, fun: (this: void) => void): void
    registerMouseEvent(handle: any, sync: boolean, fun: (this: void, mouseEventInfo: MouseEventInfo) => void): void;
    registerUnitEvent(handle: any, whichUnit: any, whichEvent: UnitEvent): void
    registerSyncData(handle: any, key: string): void
    registerWindowResizeEvent(handle: any, sync: boolean, fun: (this: void) => void): void;
    reset(handle: any) : void;
    bindHandle(handle: any): void;
    equal(handle1: any, handle2: any): boolean
    isValid(handle: any): boolean
    destroy(handle: any): void

    getDamageInfo(): DamageInfo;
    getTransInfo(): TransInfo;
    getConstructInfo(): ConstructInfo;
    getWheelInfo(): WheelInfo;
    getUpdateInfo(): UpdateInfo;
    getSelectInfo(): SelectInfo;
    getAttackInfo(): AttackInfo;
    getManipulatingItemInfo(): ManipulatingItemInfo;
    getSellItemInfo(): SellItemInfo;
    getSpellInfo(): SpellInfo;
    getLevelUpInfo(): LevelUpInfo;
    getDeadInfo(): DeadInfo;
    getInputInfo(): InputInfo;
    getKeyEventInfo(): KeyEventInfo;
    getMouseEventInfo(): MouseEventInfo;
    getPlayerExitInfo(): PlayerExitInfo;
    getSyncDataInfo(): SyncDataInfo;
    syncData(key: string, str: string): void
}
